package com.hytc.mymall.db;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2016/12/1.
 */

public class DBOpenHelper extends SQLiteOpenHelper
{
    public static final String DBNAME = "ydgy.db";
    public static final int VERSION = 2;
    public static DBOpenHelper openHelper;

    public DBOpenHelper(final Context context) {
        super(context, "ydgy.db", (SQLiteDatabase.CursorFactory)null, 2);
    }

    public static DBOpenHelper getInstance(final Context context) {
        synchronized (DBOpenHelper.class) {
            if (DBOpenHelper.openHelper == null) {
                DBOpenHelper.openHelper = new DBOpenHelper(context);
            }
            return DBOpenHelper.openHelper;
        }
    }

    public void onCreate(final SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS stayopeninvoice (id integer primary key autoincrement, invoiceNo varchar, money varchar)");
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS accountinfo (id integer primary key autoincrement, account varchar, style integer)");
    }

    public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int n, final int n2) {
        try {
            sqLiteDatabase.execSQL("DROP TABLE IF EXISTS stayopeninvoice");
            this.onCreate(sqLiteDatabase);
        }
        catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}
